package qhLoading.loaders 
{
	import flash.events.*;
    import flash.utils.*;
	import qhLoading.info.ResourceInfo;
	
	/**
	 * ...
	 * @author gcxk721
	 */
	public class BaseLoader extends QhLoader 
	{
		
		public var data:Object;

        public function BaseLoader()
        {
            
        }

        public function getClass() : Class
        {
            return BaseLoader;
        }

        override public function load(url : String, resInfo : ResourceInfo) : void
        {
            if (resInfo != null )
            {
				var bytes : ByteArray = resInfo.cacheBytes;
                if (bytes != null)
                {
                    _resourceInfo = resInfo;
                    initialize(bytes);
					return;
                }
            }
            super.load(url, resInfo);
        }

        override protected function streamloadComplete(bytes : ByteArray) : void
        {
            if (_resourceInfo)
            {
                _resourceInfo.cacheBytes = bytes;
            }
        }

        override protected function onIOErrorHandler(event:ErrorEvent) : void
        {
            if (_resourceInfo)
            {
                _resourceInfo.isLoaded = false;
                _resourceInfo.isLoading = false;
            }
            super.onIOErrorHandler(event);
        }

        override protected function onLoadCompleteHandler() : void
        {
            if (_resourceInfo)
            {
                _resourceInfo.isLoaded = true;
                _resourceInfo.isLoading = false;
            }
            super.onLoadCompleteHandler();
        }
		
	}

}